﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using perfume.Models.DB;

namespace perfume.Controllers
{ 
    public class Export_check_detailController : Controller
    {
        private perfume_dbEntities db = new perfume_dbEntities();

        //
        // GET: /Export_check_detail/

        public ViewResult Index()
        {
            var export_check_detail = db.export_check_detail.Include("export_check").Include("product");
            return View(export_check_detail.ToList());
        }

        //
        // GET: /Export_check_detail/Details/5

        public ViewResult Details(int id)
        {
            export_check_detail export_check_detail = db.export_check_detail.Single(e => e.export_check_id == id);
            return View(export_check_detail);
        }

        //
        // GET: /Export_check_detail/Create

        public ActionResult Create()
        {
            ViewBag.export_check_id = new SelectList(db.export_check, "export_check_id", "username");
            ViewBag.product_id = new SelectList(db.products, "product_id", "product_name");
            return View();
        } 

        //
        // POST: /Export_check_detail/Create

        [HttpPost]
        public ActionResult Create(export_check_detail export_check_detail)
        {
            if (ModelState.IsValid)
            {
                db.export_check_detail.AddObject(export_check_detail);
                db.SaveChanges();
                return RedirectToAction("Index");  
            }

            ViewBag.export_check_id = new SelectList(db.export_check, "export_check_id", "username", export_check_detail.export_check_id);
            ViewBag.product_id = new SelectList(db.products, "product_id", "product_name", export_check_detail.product_id);
            return View(export_check_detail);
        }
        
        //
        // GET: /Export_check_detail/Edit/5
 
        public ActionResult Edit(int id)
        {
            export_check_detail export_check_detail = db.export_check_detail.Single(e => e.export_check_id == id);
            ViewBag.export_check_id = new SelectList(db.export_check, "export_check_id", "username", export_check_detail.export_check_id);
            ViewBag.product_id = new SelectList(db.products, "product_id", "product_name", export_check_detail.product_id);
            return View(export_check_detail);
        }

        //
        // POST: /Export_check_detail/Edit/5

        [HttpPost]
        public ActionResult Edit(export_check_detail export_check_detail)
        {
            if (ModelState.IsValid)
            {
                db.export_check_detail.Attach(export_check_detail);
                db.ObjectStateManager.ChangeObjectState(export_check_detail, EntityState.Modified);
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            ViewBag.export_check_id = new SelectList(db.export_check, "export_check_id", "username", export_check_detail.export_check_id);
            ViewBag.product_id = new SelectList(db.products, "product_id", "product_name", export_check_detail.product_id);
            return View(export_check_detail);
        }

        //
        // GET: /Export_check_detail/Delete/5
 
        public ActionResult Delete(int id)
        {
            export_check_detail export_check_detail = db.export_check_detail.Single(e => e.export_check_id == id);
            return View(export_check_detail);
        }

        //
        // POST: /Export_check_detail/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {            
            export_check_detail export_check_detail = db.export_check_detail.Single(e => e.export_check_id == id);
            db.export_check_detail.DeleteObject(export_check_detail);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}